package me.bay.gt.java;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class Application {
    public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String DB_URL = "jdbc:mysql://localhost:3306/hero";
    public static final String DB_USER = "root";
    public static final String DB_PASSWORD = "";

    public static void main(String[] args) throws Exception {
        Class.forName(DB_DRIVER);
//        JDBC1Exercise jdbc1Exercise = new JDBC1Exercise(DB_URL, DB_USER, DB_PASSWORD);
//        System.out.println(jdbc1Exercise.selectById(10014));
//        jdbc1Exercise.insert(createHero4Insert());
//        jdbc1Exercise.updateById(createHero4Update());
//        jdbc1Exercise.removeById(10070);

//        JDBC2Exercise jdbc2Exercise = new JDBC2Exercise(DB_URL, DB_USER, DB_PASSWORD);
//        jdbc2Exercise.insert(createHero4Insert());
//        jdbc2Exercise.insert(createHeroes4InsertBatch());

        JDBC3Exercise jdbc3Exercise = new JDBC3Exercise(DB_URL, DB_USER, DB_PASSWORD);
        jdbc3Exercise.insert(createHeroes4InsertBatch());
    }

    static Hero createHero4Insert() {
        Hero hero = new Hero();
        hero.setName("令狐冲");
        hero.setHpMax(7891f);
        hero.setHpGrowth(315f);
        hero.setHpStart(3917f);
        hero.setMpMax(1746f);
        hero.setMpGrowth(94f);
        hero.setMpStart(430f);
        hero.setAttackMax(321f);
        hero.setAttackGrowth(11.57f);
        hero.setAttackStart(159f);
        hero.setDefenseMax(321f);
        hero.setDefenseGrowth(12f);
        hero.setDefenseStart(159f);
        hero.setHp5sMax(397f);
        hero.setHp5sGrowth(21f);
        hero.setHp5sStart(101f);
        hero.setMp5sMax(98f);
        hero.setMp5sGrowth(3f);
        hero.setMp5sStart(51f);
        hero.setAttackSpeedMax(0f);
        hero.setAttackRange("近战");
        hero.setRoleMain("刺客");
        hero.setRoleAssist("战士");
        hero.setBirthdate(LocalDate.parse("1797-03-12"));
        return hero;
    }

    static List<Hero> createHeroes4InsertBatch() {
        List<Hero> heroes = new ArrayList<>();
        final String[] names = {"郭达", "史密斯", "邦德", "史泰龙"};
        for (int i = 0; i < names.length; ++i) {
            Hero hero = new Hero();
            hero.setName(names[i]);
            hero.setHpMax(7891f + i);
            hero.setHpGrowth(315f + i);
            hero.setHpStart(3917f - i);
            hero.setMpMax(1746f - i);
            hero.setMpGrowth(94f + 2*i);
            hero.setMpStart(430f + 3*i);
            hero.setAttackMax(321f + i);
            hero.setAttackGrowth(11.57f - i);
            hero.setAttackStart(159f + 3 * i);
            hero.setDefenseMax(321f + 4 * i);
            hero.setDefenseGrowth(12f + 0.5f * i);
            hero.setDefenseStart(159f + 0.1f * i);
            hero.setHp5sMax(397f + 0.33f * i);
            hero.setHp5sGrowth(21f + 0.12f * i);
            hero.setHp5sStart(101f + 0.23f * i);
            hero.setMp5sMax(98f + 0.12f * i);
            hero.setMp5sGrowth(3f + 0.03f * i);
            hero.setMp5sStart(51f + 0.01f * i);
            hero.setAttackSpeedMax(0f + 0.02f * i);
            hero.setAttackRange("近战");
            hero.setRoleMain("刺客");
            hero.setRoleAssist("战士");
            hero.setBirthdate(LocalDate.parse("1797-03-1" + i));

            heroes.add(hero);
        }
        return heroes;
    }

    static Hero createHero4Update() {
        Hero hero = new Hero();
        hero.setId(10001);
        hero.setName("钟有艳");
        hero.setBirthdate(LocalDate.parse("2021-04-21"));
        return hero;
    }
}
